package edu.xidian.bdilab.jrbigdata.controller.admin;

import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.service.admin.adminlogin.AdminLoginService;
import edu.xidian.bdilab.jrbigdata.util.DecryptUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@CrossOrigin
@RestController
@Api(tags = {"adminlogin-管理员登录功能"})
public class AminLoginController {


    @Autowired
    AdminLoginService adminLoginService;

    @RequestMapping(value = "admin/login", method = RequestMethod.POST)
    public ResponseResult login(@RequestParam String userName,
                                @RequestParam String password,
                                HttpSession session)throws Exception{
        String md5Password = DecryptUtils.getMd5(password);
        ResponseResult responseResult=adminLoginService.adminLogin(userName,md5Password);
        if (responseResult.getMeta().getSuccess()){
            session.setAttribute("user_name",userName);
            System.out.println("user_name="+session.getAttribute("user_name"));
            System.out.println("sessionID="+session.getId());
            return responseResult;
        }else {
            return responseResult;
        }
    }

}
